package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.module.entity.ApartmentFacility;
import com.atguigu.lease.module.entity.FacilityInfo;
import com.atguigu.lease.web.admin.mapper.ApartmentFacilityMapper;
import com.atguigu.lease.web.admin.mapper.FacilityMapper;
import com.atguigu.lease.web.admin.service.ApartmentFacilityService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ApartmentFacilityServiceImpl extends ServiceImpl<ApartmentFacilityMapper, ApartmentFacility> implements ApartmentFacilityService {

    @Autowired
    private ApartmentFacilityMapper apartmentFacilityMapper;

    @Autowired
    private FacilityMapper facilityMapper;


    @Override
    public List<FacilityInfo> getApartmentFacilityListByApartmentId(Long id){
        List<ApartmentFacility> apartmentFacilityList = super.list(new LambdaQueryWrapper<ApartmentFacility>().eq(ApartmentFacility::getApartmentId, id));
        if(apartmentFacilityList == null || apartmentFacilityList.size()<=0){
            return null;
        }
        //这个方法是用mybatisPlus内置api 不需要写sql语句
        List<FacilityInfo> facilityInfoList = facilityMapper.selectList(new LambdaQueryWrapper<FacilityInfo>().in(FacilityInfo::getId, apartmentFacilityList.stream().map(ApartmentFacility::getFacilityId).collect(Collectors.toList())));
        return facilityInfoList;
    }
}
